#ifndef FRAME_PROCESSOR_H
#define FRAME_PROCESSOR_H

#include <memory>
#include <random>
#include "video_frame.h"

// 帧处理器接口
class FrameProcessor {
public:
    virtual ~FrameProcessor() = default;
    virtual std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) = 0;
    virtual FrameStage getStage() const = 0;
};

// 采集处理器
class CaptureProcessor : public FrameProcessor {
private:
    std::mt19937 rng_;
    std::uniform_real_distribution<double> dist_; // 随机延迟分布（毫秒）

public:
    CaptureProcessor(double min_delay = 1.0, double max_delay = 5.0);
    std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) override;
    FrameStage getStage() const override { return FrameStage::CAPTURE; }
};

// 编码处理器
class EncodeProcessor : public FrameProcessor {
private:
    std::mt19937 rng_;
    std::uniform_real_distribution<double> dist_; // 随机延迟分布（毫秒）

public:
    EncodeProcessor(double min_delay = 5.0, double max_delay = 20.0);
    std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) override;
    FrameStage getStage() const override { return FrameStage::ENCODE; }
};

// 发送处理器
class SendProcessor : public FrameProcessor {
private:
    std::mt19937 rng_;
    std::uniform_real_distribution<double> dist_; // 随机延迟分布（毫秒）

public:
    SendProcessor(double min_delay = 2.0, double max_delay = 10.0);
    std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) override;
    FrameStage getStage() const override { return FrameStage::SEND; }
};

// 接收处理器
class ReceiveProcessor : public FrameProcessor {
private:
    std::mt19937 rng_;
    std::uniform_real_distribution<double> dist_; // 随机延迟分布（毫秒）

public:
    ReceiveProcessor(double min_delay = 2.0, double max_delay = 15.0);
    std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) override;
    FrameStage getStage() const override { return FrameStage::RECEIVE; }
};

// 解码处理器
class DecodeProcessor : public FrameProcessor {
private:
    std::mt19937 rng_;
    std::uniform_real_distribution<double> dist_; // 随机延迟分布（毫秒）

public:
    DecodeProcessor(double min_delay = 5.0, double max_delay = 25.0);
    std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) override;
    FrameStage getStage() const override { return FrameStage::DECODE; }
};

// 渲染处理器
class RenderProcessor : public FrameProcessor {
private:
    std::mt19937 rng_;
    std::uniform_real_distribution<double> dist_; // 随机延迟分布（毫秒）

public:
    RenderProcessor(double min_delay = 1.0, double max_delay = 8.0);
    std::shared_ptr<VideoFrame> process(std::shared_ptr<VideoFrame> frame) override;
    FrameStage getStage() const override { return FrameStage::RENDER; }
};

// 处理管道
class ProcessingPipeline {
private:
    std::vector<std::unique_ptr<FrameProcessor>> processors_;

public:
    ProcessingPipeline();
    
    // 添加处理器到管道
    void addProcessor(std::unique_ptr<FrameProcessor> processor);
    
    // 处理帧并传递到下一个阶段
    std::shared_ptr<VideoFrame> processFrame(std::shared_ptr<VideoFrame> frame);
};

#endif // FRAME_PROCESSOR_H
